package com.mofang.powerdekorhelper.witget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

/**
 * Created by luofei on 2017/5/14 0014.
 */

public class SlowlyScrollView extends ScrollView {

    private ScrollBottomListener scrollBottomListener;

    public SlowlyScrollView(Context context) {
        super(context);
    }

    public SlowlyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SlowlyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void fling(int velocityY) {
        super.fling(velocityY / 3);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt){
        if(t + getHeight() >=  computeVerticalScrollRange()){
            //ScrollView滑动到底部了
             if (scrollBottomListener != null){
                 scrollBottomListener.scrollBottom();
             }
        }
    }

    public void setScrollBottomListener(ScrollBottomListener scrollBottomListener){
        this.scrollBottomListener = scrollBottomListener;
    }

    public interface ScrollBottomListener{
        public void scrollBottom();
    }
}
